package com.cskaoyan.shopping.api;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.commons.result.ServiceCallResponse;
import com.cskaoyan.mall.commons.result.ServiceCallResponseUtil;
import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemRequestRemote;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.shopping.service.ICartOrderService;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @auther cskaoyan
 * @date 2022/8/24:14:56
 */
@RestController
public class OrderApiImpl {

    @Autowired
    ICartOrderService cartOrderService;

    @Autowired
    IProductService productService;


    @GetMapping(value = "/rpc/product/detail")
    ServiceCallResponse<ProductDetailDto> getProductDetail(@RequestParam("id") Long id) {
        ProductDetailDto productDetail = productService.getProductDetail(id);
        ServiceCallResponseUtil<ProductDetailDto> responseUtil = new ServiceCallResponseUtil<>();
        return responseUtil.ok(productDetail);
    }

    @GetMapping("/rpc/product/status")
    ServiceCallResponse<Integer> getProductStatus(@RequestParam("id") Long id) {
        Integer productStatus = productService.getProductStatus(id);
        ServiceCallResponseUtil<Integer> responseUtil = new ServiceCallResponseUtil<>();
        return responseUtil.ok(productStatus);
    }

    //@DeleteMapping("rpc/cart/items")
    //void clearCartItemByUserID(ClearCartItemRequest request) {
    //    Long userId = request.getUserId();
    //}
    @DeleteMapping(value = "/rpc/cart/items")
    public ResponseData clearCartItemByUserID(@RequestBody ClearCartItemRequestRemote request){
        cartOrderService.clearCartItemByUserID(request);
        return new ResponseUtil<>().setData(null);
    }


}
